import { request } from "@/utils/service"
import * as Student from "./types/student"

/** 增 */
export function addStudentDataApi(data: Student.IAddStudentRequestData) {
  return request<Student.AddStudentResponseData>({
    url: "student/add",
    method: "post",
    data
  })
}

export function addStudentGraduateDataApi(certificateNo: string) {
  return request<Student.AddStudentResponseData>({
    url: `student/graduate/${certificateNo}`,
    method: "put"
  })
}

/** 删 */
export function deleteStudentDataApi(id: number) {
  return request<Student.DeleteStudentResponseData>({
    url: `student/deleteById/${id}`,
    method: "delete"
  })
}

/** 改 */
export function updateStudentDataApi(data: Student.IUpdateStudentRequestData) {
  return request<Student.UpdateStudentResponseData>({
    url: `student/update`,
    method: "put",
    data
  })
}

/**
 * 条件查询
 * @param data 查询参数
 */
export function getStudentDataApi(data: Student.IGetStudentRequestData) {
  return request<Student.GetStudentResponseData>({
    url: `student/getList`,
    method: "post",
    data
  })
}

/**
 * 获取学员结业证书
 * @param id 身份证号
 */
export function getStudentByCardIdApi(data: { id: string; studentId: number | undefined }) {
  return request<Student.GetStudentByCardIdResponseData>({
    url: `student_user/getStudentByCardId`,
    method: "get",
    params: { identityCardId: data.id, studentId: data.studentId }
  })
}

/**
 * 获取班级证书
 * @param classId
 */
export function getGraduateInfoApi(classId: number) {
  return request<Student.GetGraduateInfoResponseData>({
    url: `student/getGraduateInfo`,
    method: "get",
    params: { classId }
  })
}

/**
 * 获取添加模板
 */
export function getExcelTemplateApi() {
  return request<{ blob: Blob; fileName: string }>({
    url: `student/getExcelTemplate`,
    responseType: "blob",
    method: "get"
  })
}

/**
 * 批量导入学员
 * @param params
 * @param file
 */
export function importStudentsApi(
  params: { classId: number; enrollmentTime: number; graduateTime: number },
  file: File
) {
  return request<{ blob: Blob; fileName: string }>({
    url: `student/importStudents`,
    method: "post",
    params,
    data: { file }
  })
}

/**
 * 上传证件照
 * @param data
 */
export function uploadHeadImageApi(data: { identityCardId: string; identificationPhotoUrl: string }) {
  return request<{ blob: Blob; fileName: string }>({
    url: `student_user/uploadHeadImage`,
    method: "post",
    data
  })
}

/** 上传证件照 */
export function uploadIdentificationPhoto(data: FormData) {
  return request<any>({
    url: "student_user/uploadIdentificationPhoto",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  })
}

/**
 * 学员修改密码
 * @param data
 */
export function resetPasswordApi(data: { identityCardId: string; password: string }) {
  return request<{ blob: Blob; fileName: string }>({
    url: `student_user/resetPassword`,
    method: "put",
    data
  })
}

/**
 * 管理员修改密码
 * @param data
 */
export function resetAdminPasswordApi(data: { username: string; password: string }) {
  return request({
    url: `admin/resetPassword`,
    method: "put",
    data
  })
}

/**
 * 添加结业信息
 * @param data
 */
export function graduateStudentsApi(data: Student.IAddGraduateStudentsRequestData) {
  return request<Student.AddGraduateStudentsResponseData>({
    url: `student/graduateStudents`,
    method: "put",
    data
  })
}

export function exportStatisticsExcelApi(data: Student.IExportStatisticsExcelRequestData) {
  return request<{ blob: Blob; fileName: string }>({
    url: `student/exportStatisticsExcel`,
    method: "post",
    responseType: "blob",
    data
  })
}

export function disableAccountApi(identityCardId: string) {
  return request<IApiResponseData<null>>({
    url: "student/disableAccount",
    method: "put",
    params: {
      identityCardId
    }
  })
}

export function enableAccountApi(identityCardId: string) {
  return request<IApiResponseData<null>>({
    url: "student/enableAccount",
    method: "put",
    params: {
      identityCardId
    }
  })
}
